package com.jl.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jl.commons.result.PageDataInfo;
import com.jl.mapper.ComponentTypeMapper;
import com.jl.model.ComponentType;
import com.jl.model.in.ComponentTypeIn;
import com.jl.service.IComponentTypeService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 配件型号表 服务实现类
 * </p>
 *
 * @author JiangJian
 * @since 2019-04-24
 */
@Service

public class ComponentTypeServiceImpl extends ServiceImpl<ComponentTypeMapper, ComponentType> implements IComponentTypeService {

    @Override
    public void selectComponentTypeDataGrid(PageDataInfo<Map<String, Object>> pageDataInfo, QueryWrapper<ComponentType> qw) {
        Page<Map<String,Object>> page = new Page<>();
        page.setSize(pageDataInfo.getSize());
        page.setCurrent(pageDataInfo.getCurrent());
        List<Map<String,Object>> mapList =baseMapper.selectDataGrid(page,qw);
        pageDataInfo.setTotal(page.getTotal());
        pageDataInfo.setRecords(mapList);
    }

    @Override
    public boolean isComponentTypeNameUsed(String name) {
        return baseMapper.selectComponentTypeNameCount(name)>0;
    }

    @Override
    public boolean isComponentTypeNameCanUse(String name, Long componentTypeId) {
        ComponentTypeIn componentTypeIn = baseMapper.selectComponentTypeInByName(name);
        if(componentTypeIn == null){
            //如果找不到数据则表示该数据没有被使用
            return true;
        }else{
            if(componentTypeIn.getId().equals(componentTypeId)){
                //如果这个数据就是他本身则可以使用
                return true;
            }
        }
        return false;
    }
}
